<% layout('/layouts/default.html', {title: '商品类型', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-fire"></i> ${text('商品类型')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="#" class="btn btn-default" id="btnRefreshTree" title="${text('刷新')}"><i class="fa fa-refresh"></i> ${text('刷新')}</a>
				<a href="#" class="btn btn-default" id="btnExpandTreeNode" title="${text('展开一级')}"><i class="fa fa-angle-double-down"></i> ${text('展开')}</a>
				<a href="#" class="btn btn-default" id="btnCollapseTreeNode" title="${text('折叠全部')}"><i class="fa fa-angle-double-up"></i> ${text('折叠')}</a>
				<% if(hasPermi('ztGoodsType:ztGoodsTypeData')){ %>
					<a href="${ctx}/goodsType/form" class="btn btn-default btnTool" title="${text('新增类型')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${goodsType}" action="${ctx}/goodsType/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('类型编码')}：</label>
					<div class="control-inline">
						<#form:input path="viewCode" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('类型名称')}：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="200" class="form-control width-120"/>
					</div>
				</div>
			
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>			
			<table id="dataGrid"></table>
		</div>
	</div>
</div>
<% } %>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text('类型名称')}', name:'name', index:'a.name', width:250, align:"left", frozen:true, formatter: function(val, obj, row, act){
				return '( '+row.viewCode+' ) '+'<a href="${ctx}/goodsType/form?goodsCode='+row.goodsCode+'" class="btnList" data-title="${text('编辑类型')}">'+(val||row.id)+'</a>';
			}},
		{header:'${text('上架数量')}', name:'putaway', index:'a.putaway', width:90, align:"center"},
		{header:'${text('下架数量')}', name:'forSale', index:'a.forSale', width:90, align:"center"},
		{header:'${text('备上架数量')}', name:'soldOut', index:'a.soldOut', width:90, align:"center"},
		{header:'${text('自动下架数量')}', name:'automaticDown', index:'a.automaticDown', width:90, align:"center"},
		{header:'${text('类型图片')}', name:'img', index:'a.img', width:100, align:"center",frozen:true, formatter: function(val, obj, row, act){
				return '<img style="width:43px;height:43px;" src="'+val+'"></img>';
			}},

		{header:'${text('排序号')}', name:'treeSort', index:'a.tree_sort', width:100, align:"center",formatter: function(val, obj, row, act){
				return  row.treeSort+'&nbsp;<span onclick="goodsCode('+row.id+')" data-title="${text('编辑排序号')}"><i class="fa fa-pencil"></i></span>';
			}},
		/*{header:'${text('更新时间')}', name:'updateDate', index:'a.update_date', width:150, align:"center"},*/
		{header:'${text('备注信息')}', name:'remarks', index:'a.remarks', width:190, align:"center"},
		{header:'${text('类型模块')}', name:'typeName',  width:140, align:"center"},
		{header:'${text('上架状态')}', name:'state', index:'a.state', width:100, align:"center", formatter: function(val, obj, row, act){
				var sj = js.getDictLabel(${@DictUtils.getDictListJson('zt_sj_type')}, val, '${text('未上架')}', true);
				if(row.state=='0'){
					sj='<font color="#FF7F00">'+sj+'</font>';
				}else if(row.state=='1'){
					//sj='<font color="green">'+sj+'</font>';
				}else if(row.state=='2'){
					sj='<font color="red">'+sj+'</font>';
				}
				return sj;
			}},
		{header:'${text('操作')}', name:'actions', width:150, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('ztGoodsType:ztGoodsTypeData')){ %>
			if (row.state == 0){
				actions.push('<a href="${ctx}/goodsType/enable?id='+row.id+'&treeLevel='+row.treeLevel+'" class="btnList" title="${text('商品类型上架')}" data-confirm="${text('确认要上架该类型吗？')}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
			}
			if (row.state == 1){
				actions.push('<a href="${ctx}/goodsType/disable?id='+row.id+'&treeLevel='+row.treeLevel+'"class="btnList" title="${text('商品类型下架')}" data-confirm="${text('确认要下架该类型吗？')}"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
			}
			if (row.state == 2){
				actions.push('<a href="${ctx}/goodsType/enable?id='+row.id+'&treeLevel='+row.treeLevel+'"class="btnList" title="${text('商品类型上架')}" data-confirm="${text('确认要上架该类型吗？')}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
			}
				actions.push('<a href="${ctx}/goodsType/form?goodsCode='+row.goodsCode+'" class="btnList" title="${text('编辑类型')}"><i class="fa fa-pencil"></i></a>&nbsp;');
				
				actions.push('<a href="${ctx}/goodsType/delete?goodsCode='+row.goodsCode+'" class="btnList" title="${text('删除类型')}" data-confirm="${text('确认要删除该类型及所有子类型吗？')}" data-deltreenode="'+row.id+'"><i class="fa fa-trash-o"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/goodsType/form?parentCode='+row.id+'" class="btnList" title="${text('新增下级类型')}"><i class="fa fa-plus-square"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/goodsType/setSk?goodsCode='+row.goodsCode+'" class="btnList" title="${text('折扣定价')}"><i class="fa fa-building"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/goodsType/setMle?goodsCode='+row.goodsCode+'" class="btnList" title="${text('毛利额定价')}"><i class="fa fa-building-o"></i></a>&nbsp;');

				<% } %>
			return actions.join('');
		}}
	],
	treeGrid: true,			// 启用树结构表格
	defaultExpandLevel: 0,	// 默认展开的层次
	expandNodeClearPostData: 'viewCode,name,', // 展开节点清理请求参数数据（一般设置查询条件的字段属性，否则在查询后，不能展开子节点数据）	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
function goodsCode(date) {
	js.layer.open({
		type: 1
		,area: ['250px']
		,title: '提示'
		,content: '<input style="overflow:auto;display: block;margin: 0 auto;" type="text" oninput="value=value.replace(/[^\\d]/g,\'\')"  id="treeSort"  maxlength="9" class="form-control width-120"/>'
		,btn: ['确定','取消']
		,btnAlign: 'c' //按钮居中
		,shade: 0 //不显示遮罩
		,btn1: function(index, layero){
			var treeSort=layero.find('#treeSort').val()
			if(treeSort!=""&&treeSort!=null&&treeSort!=undefined){
				js.ajaxSubmit("${ctx}/goodsType/updateTreeSort",{
					id:String(date),
					treeSort:Number(treeSort)
				}, function(data){
					js.showMessage(data.message);
					if(data.result == Global.TRUE){
						js.layer.closeAll();
						page();
					}
				}, "json");
			}
		}
	});
}
</script>